package design_pattern.momento.test3;

/**
 * Created by WeiDingKuo on 2017/10/27 15:22
 * <p>
 * 备忘录模式--多重检查点（待完善）
 */
public class Orignator {
    private String name;
    private int currentIndex = 0;

    public MomentoIF createMomento() {
        currentIndex++;
        return new Momento(this.getName());
    }

    public void restoreMoment(MomentoIF momentoIF) {
        this.name = ((Momento) momentoIF).getName();
    }

    /**
     * 黑盒备忘录
     */
    private class Momento implements MomentoIF {
        private String name;

        public Momento(String name) {
            this.name = name;
        }

        public String getName() {
            return this.name;
        }
    }

    /**
     * 辅助方法
     *
     * @param careTaker
     */
    public void printName(CareTaker careTaker) {
        careTaker.getMomentoIFList().forEach(momentoIF -> System.out.println(((Momento) momentoIF).getName()));
    }

    public String getName() {
        return name;
    }

    public int getCurrentIndex() {
        return currentIndex;
    }

    public void setName(String name, CareTaker careTaker) {
        this.name = name;
        careTaker.removeDisabledMomento(this.currentIndex);
    }
}
